import React from 'react';
import { inject, observer } from 'mobx-react';
import {WeaTableNew} from 'comsMobx';
const WeaTable = WeaTableNew.WeaTable;
import allStores from '../../stores/index'

import { WeaErrorPage, WeaTools } from 'ecCom';
import {WeaTop,WeaTab,WeaRightMenu} from 'ecCom';
import {Input,Button,Alert,Spin,Icon,Modal,message} from 'antd';
import {Condition,getAdButtons} from './ListConditionCharts';

import isEmpty from 'lodash/isEmpty'
import forEach from 'lodash/forEach'
import {routerShape} from 'react-router';

import FnaBarChart from '../../public/FnaBarChart';
import FnaPieChart from '../../public/FnaPieChart';

/**
 * 部门
 */
@inject('fnaDepartmentExpenseStore')
@observer
class FnaDepartmentExpense extends React.Component {
	static contextTypes = {
	    router: routerShape
	};

	constructor(props) {
		super(props);
	}

	componentDidMount() {
		var data = this.props.location.query;
		var {title,name,text} = data;
		let {setRouter,initDatas} = this.props.fnaDepartmentExpenseStore;
		let {router} = this.context;
        setRouter(router);	
        initDatas();//初始化数据
	}
	
	componentWillReceiveProps(nextProps) {
		
	}
	shouldComponentUpdate(nextProps, nextState) {
		
		return true;
	}
	componentWillUnmount() {
		//组件卸载时一般清理一些状态

	}

	render() {
		
		const { fnaDepartmentExpenseStore } = this.props;
		const {title,showSearchAd,loading,setShowSearchAd,
			   charFlag,maxAmount,xAxisData,barDatas,data,
			   legendData,pieDatas,permisflag,havePermis} = fnaDepartmentExpenseStore;                                             
		
			   if(permisflag == "failed"){
			   		message.warning('您无权查看这些部门费用');
			   }

			   if(havePermis == "1"){
					message.warning('其中有部门费用您无权查看');
			   }
		return (
			<div>
				<WeaTop
					title={title}
					loading={loading}
					icon={<i className='icon-coms-Finance'/>}
					iconBgcolor='#f14a2d'
					buttons={this.getTopButton()}
					buttonSpace={10}
					showDropIcon={true}
					dropMenuDatas={this.getRightMenu()}
				>
				</WeaTop>
				<WeaTab
					buttonsAd={getAdButtons(fnaDepartmentExpenseStore)}
					searchType={['advanced']}
					searchsBaseValue=""//默认值
					setShowSearchAd={bool=>{setShowSearchAd(bool)}}
                    hideSearchAd={()=> setShowSearchAd(false)}
                    searchsAd={
                            <Condition listStore={fnaDepartmentExpenseStore} onEnterSearch={()=>{this.enterSearch();}}/>
                    }
                    showSearchAd={showSearchAd}
				/>

				<div style={charFlag?{display:'block'}:{display:'none'}}>
					<div style={{display:'innerBlock',width:'50%',float:'left'}}>
					    <FnaBarChart
						     data={data}
						     maxAmount={maxAmount}
						     xAxisData={xAxisData}
						     barDatas={barDatas}
						     mainStore={fnaDepartmentExpenseStore}
						/>
					</div>
					<div style={{display:'innerBlock',width:'50%',float:'left'}}>
						<FnaPieChart
						     data={data}
						     legendData={legendData}
						     pieDatas={pieDatas}
						     mainStore={fnaDepartmentExpenseStore}
						/>
					</div>
				</div>
			</div>
		)
	}

	/**
	*获取TOP
	*/
	getTopButton(){

	}

	/**
	*获取右键菜单
	*/
	getRightMenu(){

	}

	/**
	* 高级搜索回车搜索
	*/
	enterSearch = () => {
		const {fnaDepartmentExpenseStore} = this.props;
		const {doSearch,setShowSearchAd} = fnaDepartmentExpenseStore;
		doSearch();
		setShowSearchAd(false);
	}
}


export default WeaTools.tryCatch(React,
	props => <WeaErrorPage msg={ props.error ? props.error : '对不起，该页面异常，请联系管理员！'} />,
	{error: ""}
)(FnaDepartmentExpense);




